package com.lei.sqlGoodsJsp.dao.Impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.lei.sqlGoodsJsp.dao.UserLoginDao;
import com.lei.sqlGoodsJsp.entity.Goods;
import com.lei.sqlGoodsJsp.entity.LoginUserEntity;

public class UserLoginImpl implements UserLoginDao {

	@Override
	public List<LoginUserEntity> listAll() {
		Connection conn = JDBC.getConn();
//		 String sql = "select * from table_user where user_name='"+userName+"' and pass_word='"+passWord+"'";
		String sql = "select id, user_name,pass_word,user_name_one from table_user";
		PreparedStatement ps = null;
		List<LoginUserEntity> list = new ArrayList();
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				int i = 1;
				Long id = rs.getLong(i++);
				String userName = rs.getString(i++);
				String password = rs.getString(i++);
				String userNameOne = rs.getString(i++);
				list.add(new LoginUserEntity(id, userName, password, userNameOne, null));
			}
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JDBC.close(null, ps, conn);
		}
		return null;
	}

}
